package com.hwd.gmall.product.controller;

import com.hwd.gmall.common.result.Result;
import com.hwd.gmall.product.util.FastDfsUtil;
import org.csource.common.MyException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


/**
 * 文件上传的控制层
 *
 * @author 黄伟东/Victor
 * @date 2022/4/19 16:58
 */
@RestController
@RequestMapping(value = "/admin/product")
public class FileController {

    @Value("${fileServer.url}")
    private String fileServerUrl;

    /**
     * 文件上传
     *
     * @param file 文件对象
     * @return com.hwd.gmall.common.result.Result<java.lang.String>
     */
    @PostMapping(value = "/fileUpload")
    public Result<String> fileUpload(@RequestParam("file") MultipartFile file) throws IOException, MyException {
        return Result.ok(fileServerUrl + FastDfsUtil.uploadFile(file));

    }
}
